import useDateList, {
  useDateListRefs
} from "@/components/Overlay/components/DatePicker/useDateList";
import { updateParams } from "@/components/Overlay/hooks/useUtils";
import useFetchWinRes, { useFetchWinResRefs } from "./useFetchWinRes";
interface DateRollType {
  toggleShow(): void;
}
const useFetchDateList = defineStore("drawHist-fetchDateList", () => {
  const { fetchDateList1 } = useDateList();
  const { dateList, dateParams } = useDateListRefs();
  const { fetchWinRes } = useFetchWinRes();
  const { winResParams } = useFetchWinResRefs();
  const yearRef = ref<DateRollType>();
  const curHistDate = ref("");
  function toggleYear() {
    yearRef.value && yearRef.value.toggleShow();
  }

  function updateYear(year: any) {
    updateParams(
      {
        draw_year: year
      },
      dateParams.value
    );
    updateParams(
      {
        draw_year: year,
        draw_id: ""
      },
      winResParams.value
    );
    curHistDate.value = "";
    fetchDateList1();
    fetchWinRes();
  }

  return {
    dateList,
    toggleYear,
    updateYear,
    yearRef,
    curHistDate,
    fetchDateList1,
    dateParams
  };
});
export const useFetchDateListRefs = () => storeToRefs(useFetchDateList());
export default useFetchDateList;
